package cn.power.win.win_power.utils;

import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import cn.power.win.win_power.acitivity.MainActivity;
import cn.power.win.win_power.fragment.ActualTimeFragment;
import cn.power.win.win_power.fragment.HistoryFragment;
import cn.power.win.win_power.fragment.NodeFragment;
import cn.power.win.win_power.fragment.SettingFragment;

/**
 *
 */
public class MyFragmentPagerAdapter extends FragmentPagerAdapter {

    private final int PAGER_COUNT = 4;
    private NodeFragment myFragment1 = null;
    private ActualTimeFragment myFragment2 = null;
    private SettingFragment myFragment3 = null;
    private HistoryFragment myFragment4 = null;


    public MyFragmentPagerAdapter(FragmentManager fm) {
        super(fm);
        myFragment1 = new NodeFragment();
        myFragment2 = new ActualTimeFragment();
        myFragment3 = new SettingFragment();
        myFragment4 = new HistoryFragment();
    }
 /*   @Override
    public long getItemId(int position) {
        return mTabItemIds.get(position).hashCode();
    }*/

    @Override
    public int getCount() {
        return PAGER_COUNT;
    }

    @Override
    public Object instantiateItem(ViewGroup vg, int position) {
        return super.instantiateItem(vg, position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        System.out.println("position Destory" + position);
        super.destroyItem(container, position, object);
    }

/*    @Override
    public int getItemPosition(@NonNull Object object) {
        return super.getItemPosition(object);
    }*/

    @Override
    public Fragment getItem(int position) {
        Fragment fragment = null;
        switch (position) {
            case MainActivity.PAGE_ONE:
                fragment = myFragment1;
                break;
            case MainActivity.PAGE_TWO:
                fragment = myFragment2;
                break;
            case MainActivity.PAGE_THREE:
                fragment = myFragment3;
                break;
            case MainActivity.PAGE_FOUR:
                fragment = myFragment4;
                break;
        }
        return fragment;
    }


}

